//
//  TopicPingTableViewCell.m
//  A_Object_Netease
//
//  Created by 张春洋  on 16/1/20.
//  Copyright © 2016年 张春洋. All rights reserved.
//

#import "TopicPingTableViewCell.h"
//#import "AllHeadPrefixHeader.pch"
#define KUAN [UIScreen mainScreen].bounds.size.width /375
#define GAO [UIScreen mainScreen].bounds.size.height /667


@implementation TopicPingTableViewCell



#pragma mark - 初始化

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // beijing
        self.beijing = [[UIImageView alloc] init];
        _beijing.image = [UIImage imageNamed:@"bg"];
        [self.contentView addSubview:_beijing];
        
        // userTou
        self.userTou = [[UIImageView alloc] init];
//        _userTou.backgroundColor = [UIColor redColor];
        [self.beijing addSubview:_userTou];
        
        // userName
        self.userMing = [[UILabel alloc] init];
        _userMing.font = [UIFont systemFontOfSize:12];
//        _userMing.backgroundColor = [UIColor blueColor];
        [self.beijing addSubview:_userMing];
        
        // question
        self.question = [[UILabel alloc] init];
        _question.numberOfLines = 0;
        _question.font = [UIFont systemFontOfSize:14];
//        _question.backgroundColor = [UIColor purpleColor];
        [self.beijing addSubview:_question];
        
        // zhong
        self.zhong = [[UILabel alloc] init];
//        _zhong.backgroundColor = [UIColor redColor];
        _zhong.text = @"........................................................................";
        _zhong.textColor = [UIColor redColor];
        [self.beijing addSubview:_zhong];
        
        // tou
        self.tou = [[UIImageView alloc] init];
//        _tou.backgroundColor = [UIColor grayColor];
        [self.beijing addSubview:_tou];
        
        // name
        self.name = [[UILabel alloc] init];
        _name.font = [UIFont systemFontOfSize:12];
//        _name.backgroundColor = [UIColor magentaColor];
        [self.beijing addSubview:_name];
        
        // answer
        self.answer = [[UILabel alloc] init];
        _answer.numberOfLines = 0;
        _answer.font = [UIFont systemFontOfSize:14];
//        _answer.backgroundColor = [UIColor greenColor];
        [self.beijing addSubview:_answer];
        
        //
        self.fengexian = [[UIView alloc] init];
        _fengexian.backgroundColor = [UIColor blackColor];
        _fengexian.alpha = 0.2;
        [self.beijing addSubview:_fengexian];
        
        // time
        self.time = [[UILabel alloc] init];
//        _time.backgroundColor = [UIColor purpleColor];
        [self.beijing addSubview:_time];
        
        // ping
        self.ping = [[UIImageView alloc] init];
//        _ping.backgroundColor = [UIColor blueColor];
        [self.beijing addSubview:_ping];
        
        // pinglun
        self.pinglun = [[UILabel alloc] init];
//        _pinglun.backgroundColor = [UIColor redColor];
        [self.beijing addSubview:_pinglun];
        
        // zan
        self.zan = [[UIImageView alloc] init];
//        _zan.backgroundColor = [UIColor greenColor];
        [self.beijing addSubview:_zan];
        
        // support
        self.support = [[UILabel alloc] init];
//        _support.backgroundColor = [UIColor purpleColor];
        [self.beijing addSubview:_support];
        
    }
    return  self;
}
#pragma mark - 自适应高度的计算
+ (CGFloat)heightWihtText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:18]};
    CGSize s = CGSizeMake(375 - 20, 400);
    CGRect h = [text boundingRectWithSize:s options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return h.size.height;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    _userTou.frame = CGRectMake(10 *KUAN, GAO * 10, KUAN * 30, GAO * 30);
    _userMing.frame = CGRectMake(50 * KUAN, GAO * 10, KUAN * 300, GAO * 20);
    CGFloat h = [[self class] heightWihtText:_question.text];
    _question.frame = CGRectMake(50 *KUAN, GAO * 30, self.contentView.frame.size.width - 90, h *GAO);
    _zhong.frame = CGRectMake(40 *KUAN, (40 + h) * GAO, self.contentView.frame.size.width - 80, 10 *GAO);
    _tou.frame = CGRectMake(10 * KUAN, (60 + h)  *GAO, KUAN*30, GAO * 30);
    _name.frame = CGRectMake(50 * KUAN, (60 + h) *GAO, KUAN * 300, GAO * 20);
    CGFloat r = [[self class] heightWihtText:_answer.text];
    _answer.frame = CGRectMake(50 *KUAN, (80 + h) *GAO, self.contentView.frame.size.width - 90, r *GAO);
    _fengexian.frame = CGRectMake(20 *KUAN, (90 + h + r) *GAO, self.contentView.frame.size.width - 60, 1 *GAO);
    _time.frame = CGRectMake(50 *KUAN, (100 + h + r) *GAO, KUAN * 80, GAO * 20);
    _ping.frame = CGRectMake(260 *KUAN , (100 + h + r)*GAO, KUAN * 20, GAO * 20);
    _pinglun.frame = CGRectMake(280 *KUAN, (100 + h + r) *GAO, KUAN * 30, GAO * 20);
    _zan.frame = CGRectMake(300 *KUAN, (100 + h + r) *GAO, KUAN * 20, GAO * 20);
    _support.frame = CGRectMake(320 *KUAN, (100 + h + r ) *GAO,KUAN * 30, GAO * 20);
    _beijing.frame = CGRectMake(10 *KUAN,GAO * 10, self.contentView.frame.size.width - 20, (h + r + 140) *GAO);
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
